<?php

namespace app\api\controller;

use app\api\controller\send;
use app\common\controller\Api;
use think\Date;
use think\Db;
use think\Response;


class Ela extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    //http://ela.test/api/ela/test
    public function test() {
        $xml = "
				<eWMSMessage>
		<WebService_ID>ERP</WebService_ID>
		<EventID>InventoryData</EventID>
		<InventoryDataList>
			<InventoryDataInfo>
				<Inventory_ID>盤點單編號</Inventory_ID>
				<InventoryDetailDataList>
					<InventoryDetailDataInfo>
						<SerialId>盤點底稿序號</SerialId>
						<SKU>品號</SKU>
						<CarrierID>棧板編號</CarrierID>
						<LotId>批號</LotId>
						<InventoryQty>盤點數量</InventoryQty>
					</InventoryDetailDataInfo>
					<InventoryDetailDataInfo>
						<SerialId>盤點底稿序號</SerialId>
						<SKU>品號</SKU>
						<CarrierID>棧板編號</CarrierID>
						<LotId>批號</LotId>
						<InventoryQty>盤點數量</InventoryQty>
					</InventoryDetailDataInfo>
				</InventoryDetailDataList>
			</InventoryDataInfo>
		</InventoryDataList>
	</eWMSMessage>																																	";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';

//        $data2 = ['WebService_ID' => 'ERP', 'EventID' => 'SendPickUpData', 'PickUpDataList' => ['PickUpDataInfo' => ['POType' => '單別', 'POId' => '單號', 'PickUpTime' => '領料日期', 'FactoryId' => '廠別代號', 'PickUpDetailDataList' => ['PickUpDetailDataInfo' => ['0' => ['SerialId' => '序號', 'SKU' => '品號', 'LotId' => '批號', 'CheckQty' => '驗收數量', 'Item_Common3' => '工單號'], '1' => ['SerialId' => '序號', 'SKU' => '品號', 'LotId' => '批號', 'CheckQty' => ['0' => '驗收數量', '1' => '驗收數量'], 'Item_Common3' => '工單號']]]]]];
//        $strData1 = "<eWMSMessage>".$this->arrayToXml($data)."</eWMSMessage>";
//        $strData2 = "<eWMSMessage>".$this->arrayToXml($data2)."</eWMSMessage>";
//        echo '<br>'.$strData1.'<br>';
//        echo $strData2.'<br>';

    }

    //http://ela.test/api/ela/doela
    public function doela()
    {
        set_time_limit(0); //执行时间无限
        ini_set('memory_limit', '-1'); //内存无限

        ob_end_clean();
        ob_implicit_flush();
        header('X-Accel-Buffering: no');

        echo '#Begin' . date('H:i:s') . '<br>';

        $this->data1();
        $this->data2();
        $this->data3();
//        $this->data4();
        $this->data5();
        $this->data6();
        $this->data7();
        $this->data8();
        $this->data9();
        $this->data10();
        $this->data11();
//        $this->data12();
//        $this->data13();

        echo '<br>#OK ' . date('H:i:s') . '<br>';
    }

    function xmlToArray($xml)
    {
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $values;
    }

    function arrayToXml($arr)
    {
        $xml = "";
        foreach ($arr as $key => $val) {
            //---去掉key中的下标[]
            $key = preg_replace('/\[\d*\]/', '', $key);
            //----
            if (is_array($val)) {
                $xml .= "<" . $key . ">" . $this->arrayToXml($val) . "</" . $key . ">";
            } else {
                if (empty($val)) {
                    $val = "";
                }
                $val = str_replace(['<','>'], '', $val);
                $xml .= "<" . $key . ">" . $val . "</" . $key . ">";
            }
        }
        return $xml;
    }

    //数组 转 php代码字符串
    function dd_array2str($array, $lv = 1)
    {
        if (is_array($array)) {
            $str = '[' . "\n";
            foreach ($array AS $key => $value) {
                $str .= str_repeat('  ', $lv) . '\'' . $key . '\'=>' . $this->dd_array2str($value, $lv + 1) . ',' . "\n";
            }
            $str = substr($str, 0, strlen($str) - 2);
            $str .= "\n" . str_repeat('  ', $lv - 1) . ']';
            if ($lv == 1) $str .= ';';
            return $str;
        } else {
            $array = addslashes($array);
            return '\'' . $array . '\'';
        }
    }

    function sendsoap($xml) {
        try {
            $client = new \SoapClient("http://office.ecatch.com.tw:8739/eWMSMessage/mex");
            $params = array(
                "input"=> array(
                    "XML_Message"=>"<?xml version=\"1.0\" encoding=\"utf-8\"?>".$xml
                ),
            );

            $response = $client->__soapCall("eWMSService", array($params));//返回数组
        } catch (Exction $e) {
            echo print_r($e->getMessage(), true);
        }

        $elalog = new \app\admin\model\ela\Log();
        $elalog->content = $xml;
        $elalog->return = json_encode($response);

        if (isset($response->eWMSServiceResult)
            && isset($response->eWMSServiceResult->RtnCode)
            && $response->eWMSServiceResult->RtnCode == "Y") {
            $elalog->state = 1;
            $elalog->save();
        } else {
            $elalog->save();
            return false;
        }

        return true;
    }

    //http://ela.test/api/ela/data1
    //品號資料
    public function data1()
    {
        $iclist = \app\admin\model\ela\Itemcategory::where('state', '0')->limit(1000)->select();
        $data = array(
            'WebService_ID' => 'ERP',
            'EventID' => 'SendSKUData',
            'SKUDataList' => []
        );

        foreach ($iclist as $k => $ic) {
            $SKUDataInfo = "SKUDataInfo[{$k}]";
            $data['SKUDataList'][$SKUDataInfo] = array(
                'SKU' => $ic['sku'],//'品號',
                'SKUName' => $ic['skuname'],//'品名',
                'Specification' => $ic['specification'],//'規格',
                'InventoryUnit' => $ic['inventoryunit'],//'庫存單位',
                'SKUType1' => '', //$ic['skutype1'],//'[品號分類一]',
                'SKUType2' => '', //$ic['skutype2'],//'[品號分類二]',
                'SKUType3' => '',//$ic['skutype3'],//'[品號分類三]',
                'SKUType4' => '',//$ic['skutype4'],//'[品號分類四]',
                'ProductDescription' => $ic['productdescription'],//'商品描述',
                'StandardSKU' => $ic['standardsku'],//'標準途程品號',
                'StandardCodeNumber' => $ic['standardcodenumber'],//'標準途程代號',
                'MainWarehouseId' => $ic['mainwarehouseid'],//'主要庫別',
                'InventoryManagement' => $ic['inventorymanagement'],//'庫存管理',
                'LotManagement' => $ic['lotmanagement'],//'批號管理',
                'SKUAttribute' => $ic['skuattribute'],//'品號屬性',
                'Note' => $ic['note'],//'備註',
                'EffectiveDateTime' => $ic['effectivedatetime'],//'生效日期',
                'FailureDateTime' => $ic['failuredatetime'],//'失效日期',
                'InspectionMethod' => $ic['inspectionmethod'],//'檢驗方式',
            );
        }

        if (count($iclist) > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($iclist as $ic) {
                    $ic->state = 1;
                    $ic->save();
                }
            }
        }

    }

    //http://ela.test/api/ela/data2
    //品號變更資料
    public function data2() {

        $icloglist = \app\admin\model\ela\Itemcategorychangelog::where('state', '0')->select();
        $data = array(
            'WebService_ID' => 'ERP',
            'EventID' => 'SendSKUChangeData',
            'SKUChangeDataList' => []
        );

        foreach ($icloglist as $k => $iclog) {
            $SKUChangeDataInfo = "SKUChangeDataInfo[{$k}]";
            $data['SKUDataList'][$SKUChangeDataInfo] = array(
                'SKU' => $iclog['sku'],//'品號',
                'ChangeEdition' => $iclog['changeedition'],//'變更版次',
                'ChangeDateTime' => $iclog['changedatetime'],//'變更日期',
                'NewSKU' => $iclog['newsku'],//'新品名',
                'NewSpecification' => $iclog['newspecification'],//'新規格',
                'ConfirmCode' => $iclog['confirmcode'],//'確認碼',
                'FieldID' => $iclog['fieldid'],//'欄位編號',
                'NewStringFieldValue' => $iclog['newstringfieldvalue'],//'新文字型欄位值',
                'NewIntFieldValue' => $iclog['newintfieldvalue'],//'新數字型欄位值',
            );
        }

        if (count($icloglist) > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($icloglist as $iclog) {
                    $iclog->state = 1;
                    $iclog->save();
                }
            }
        }

    }

    //http://ela.test/api/ela/data3
    //採購單---同采购入库单
    public function data3()
    {
        $sql = "select deposit0_id from fa_ela_deposit1 where state = '0' group by deposit0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendBuyData',
            'BuyDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $dep0 = \app\admin\model\ela\Deposit0::get($row['deposit0_id']);
            if (!$dep0)
                continue;

            $BuyDataInfo = "BuyDataInfo[{$k}]";
            $data['BuyDataList'][$BuyDataInfo] = array(
                'POType' => $dep0['receipt'],//'單別',
                'POId' => $dep0['receipt_number'],//'單號',
                'BuyDateTime' => $dep0['date'],//'採購日期',
                'FactoryId' => $dep0['factory'],//'廠別代號',
                'BuyDetailDataList' => []
            );

            $dep1list = \app\admin\model\ela\Deposit1::where('state', '0')
                ->where('warehouse', '6408')
                ->where('deposit0_id', $row['deposit0_id'])->select();
            foreach ($dep1list as $m => $dep1) {
                $BuyDetailDataInfo = "BuyDetailDataInfo[{$m}]";
                $data['BuyDataList'][$BuyDataInfo]['BuyDetailDataList'][$BuyDetailDataInfo] = array(
                    'SerialId' => $dep1['serialid'],//'序號',
                    'SKU' => $dep1['sku'],//'品號',
                    'LotId' => $dep1['lotid'],//'批號',
                    'CheckQty' => $dep1['checkqty'],//'驗收數量'
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                //Deposit0 无法关联的，也处理为state = 1，避免下次重复操作
                foreach ($idlist as $row) {
                    $dep1list = \app\admin\model\ela\Deposit1::where('state', '0')
                        ->where('deposit0_id', $row['deposit0_id'])->select();
                    foreach ($dep1list as $m => $dep1) {
                        $dep1->state = 1;
                        $dep1->result = 1;
                        $dep1->save();
                    }
                }
            }
        }

    }

    //http://ela.test/api/ela/data4
    //採購入庫單
    public function data4() {

        $sql = "select deposit0_id from fa_ela_deposit1 where state = '0' group by deposit0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendInboundData',
            'InboundDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $dep0 = \app\admin\model\ela\Deposit0::get($row['deposit0_id']);
            if (!$dep0)
                continue;

            $InboundDataInfo = "InboundDataInfo[{$k}]";
            $data['InboundDataList'][$InboundDataInfo] = array(
                'POType' => $dep0['receipt'],//'單別',
                'POId' => $dep0['receipt_number'],//'單號',
                'InboundDateTime' => $dep0['date'],//'入庫日期',
                'FactoryId' => $dep0['factory'],//'廠別代號',
                'InboundDetailDataList' => []
            );

            $dep1list = \app\admin\model\ela\Deposit1::where('state', '0')
                ->where('warehouse', '6408')
                ->where('deposit0_id', $row['deposit0_id'])->select();
            foreach ($dep1list as $m => $dep1) {
                $InboundDetailDataInfo = "InboundDetailDataInfo[{$m}]";
                $data['InboundDataList'][$InboundDataInfo]['InboundDetailDataList'][$InboundDetailDataInfo] = array(
                    'SerialId' => $dep1['serialid'],//'序號',
                    'SKU' => $dep1['sku'],//'品號',
                    'LotId' => $dep1['lotid'],//'批號',
                    'CheckQty' => $dep1['checkqty'],//'驗收數量'
                    'Item_Common1' => $dep1['purchase'],//'採購單號',
                    'Item_Common2' => $dep1['purchase_order'],//'採購單項次'
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                //Deposit0 无法关联的，也处理为state = 1，避免下次重复操作
                foreach ($idlist as $row) {
                    $dep1list = \app\admin\model\ela\Deposit1::where('state', '0')->where('deposit0_id', $row['deposit0_id'])->select();
                    foreach ($dep1list as $m => $dep1) {
                        $dep1->state = 1;
                        $dep1->result = 1;
                        $dep1->save();
                    }
                }
            }
        }
    }

    //http://ela.test/api/ela/data5
    //領料單 fa_ela_picking0 fa_ela_picking1
    public function data5() {

        $sql = "select picking0_id from fa_ela_picking1 where state = '0' group by picking0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendPickUpData',
            'PickUpDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $pick0 = \app\admin\model\ela\Picking0::get($row['picking0_id']);
            if (!$pick0)
                continue;

            $PickUpDataInfo = "PickUpDataInfo[{$k}]";
            $data['PickUpDataList'][$PickUpDataInfo] = array(
                'POType' => $pick0['receipt'],//'單別',
                'POId' => $pick0['receipt_number'],//'單號',
                'PickUpTime' => $pick0['date'],//'入庫日期',
                'FactoryId' => $pick0['factory'],//'廠別代號',
                'PickUpDetailDataList' => []
            );

            $pick1list = \app\admin\model\ela\Picking1::where('state', '0')
                ->where('warehouse', '6408')
                ->where('picking0_id', $row['picking0_id'])->select();
            foreach ($pick1list as $m => $pick1) {
                $PickUpDetailDataInfo = "PickUpDetailDataInfo[{$m}]";
                $data['PickUpDataList'][$PickUpDataInfo]['PickUpDetailDataList'][$PickUpDetailDataInfo] = array(
                    'SerialId' => $pick1['serialid'],//'序號',
                    'SKU' => $pick1['sku'],//'品號',
                    'LotId' => $pick1['lotid'],//'批號',
                    'CheckQty' => $pick1['checkqty'],//'驗收數量'
                    'Item_Common3' => $pick1['workorder'],//'工單號',
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $pick1list = \app\admin\model\ela\Picking1::where('state', '0')->where('picking0_id', $row['picking0_id'])->select();
                    foreach ($pick1list as $m => $pick1) {
                        $pick1->state = 1;
                        $pick1->result = 1;
                        $pick1->save();
                    }
                }
            }
        }

    }

    //http://ela.test/api/ela/data6
    //退料單 fa_ela_returndan0 fa_ela_returndan1
    public function data6() {

        $sql = "select returndan0_id from fa_ela_returndan1 where state = '0' group by returndan0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendReturnData',
            'ReturnDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $return0 = \app\admin\model\ela\Returndan0::get($row['returndan0_id']);
            if (!$return0)
                continue;

            $ReturnDataInfo = "ReturnDataInfo[{$k}]";
            $data['ReturnDataList'][$ReturnDataInfo] = array(
                'POType' => $return0['receipt'],//'單別',
                'POId' => $return0['receipt_number'],//'單號',
                'PickUpTime' => $return0['date'],//'入庫日期',
                'FactoryId' => $return0['factory'],//'廠別代號',
                'ReturnDetailDataList' => []
            );

            $return1list = \app\admin\model\ela\Returndan1::where('state', '0')
                ->where('warehouse', '6408')
                ->where('returndan0_id', $row['returndan0_id'])->select();
            foreach ($return1list as $m => $return1) {
                $ReturnDetailDataInfo = "ReturnDetailDataInfo[{$m}]";
                $data['ReturnDataList'][$ReturnDataInfo]['ReturnDetailDataList'][$ReturnDetailDataInfo] = array(
                    'SerialId' => $return1['serialid'],//'序號',
                    'SKU' => $return1['sku'],//'品號',
                    'LotId' => $return1['lotid'],//'批號',
                    'CheckQty' => $return1['checkqty'],//'驗收數量'
                    'Item_Common3' => $return1['workorder'],//'工單號',
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $return1list = \app\admin\model\ela\Returndan1::where('state', '0')->where('returndan0_id', $row['returndan0_id'])->select();
                    foreach ($return1list as $m => $return1) {
                        $return1->state = 1;
                        $return1->result = 1;
                        $return1->save();
                    }
                }
            }
        }

    }

    //http://ela.test/api/ela/data7
    //生產入庫單 fa_ela_productdeposit0 fa_ela_productdeposit1
    public function data7() {

        $sql = "select productdeposit0_id from fa_ela_productdeposit1 where state = '0' group by productdeposit0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendProduceInData',
            'ProduceInDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $pro0 = \app\admin\model\ela\Productdeposit0::get($row['productdeposit0_id']);
            if (!$pro0)
                continue;

            $ProduceInDataInfo = "ProduceInDataInfo[{$k}]";
            $data['ProduceInDataList'][$ProduceInDataInfo] = array(
                'POType' => $pro0['receipt'],//'單別',
                'POId' => $pro0['receipt_number'],//'單號',
                'ReturnDateTime' => $pro0['date'],//'入庫日期',
                'FactoryId' => $pro0['factory'],//'廠別代號',
                'ProduceInDetailDataList' => []
            );

            $pro1list = \app\admin\model\ela\Productdeposit1::where('state', '0')
                ->where('warehouse', '6408')
                ->where('productdeposit0_id', $row['productdeposit0_id'])->select();
            foreach ($pro1list as $m => $pro1) {
                $ProduceInDetailDataInfo = "ProduceInDetailDataInfo[{$m}]";
                $data['ProduceInDataList'][$ProduceInDataInfo]['ProduceInDetailDataList'][$ProduceInDetailDataInfo] = array(
                    'SerialId' => $pro1['serialid'],//'序號',
                    'SKU' => $pro1['sku'],//'品號',
                    'LotId' => $pro1['lotid'],//'批號',
                    'CheckQty' => $pro1['checkqty'],//'驗收數量'
                    'Item_Common3' => $pro1['workorder'],//'工單號',
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $pro1list = \app\admin\model\ela\Productdeposit1::where('state', '0')->where('productdeposit0_id', $row['productdeposit0_id'])->select();
                    foreach ($pro1list as $m => $pro1) {
                        $pro1->state = 1;
                        $pro1->result = 1;
                        $pro1->save();
                    }
                }
            }
        }

    }

    //http://ela.test/api/ela/data8
    //調撥單 fa_ela_transfer0  fa_ela_transfer1
    public function data8() {

        $sql = "select transfer0_id from fa_ela_transfer1 where state = '0' group by transfer0_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendTransferData',
            'TransferDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $transfer0 = \app\admin\model\ela\Transfer0::get($row['transfer0_id']);
            if (!$transfer0)
                continue;

            $TransferDataInfo = "TransferDataInfo[{$k}]";
            $data['TransferDataList'][$TransferDataInfo] = array(
                'POType' => $transfer0['receipt'],//'單別',
                'POId' => $transfer0['receipt_number'],//'單號',
                'ReturnDateTime' => $transfer0['date'],//'入庫日期',
                'FactoryId' => $transfer0['factory'],//'廠別代號',
                'TransferDetailDataList' => []
            );

            $transfer1list = \app\admin\model\ela\Transfer1::where('state', '0')->where('transfer0_id', $row['transfer0_id'])->select();
            foreach ($transfer1list as $m => $transfer1) {
                if ($transfer1['warehouse_in'] == '6408' || $transfer1['warehouse_out'] == '6408' ) {
                    $TransferDetailDataInfo = "TransferDetailDataInfo[{$m}]";
                    $data['TransferDataList'][$TransferDataInfo]['TransferDetailDataList'][$TransferDetailDataInfo] = array(
                        'SerialId' => $transfer1['serialid'],//'序號',
                        'SKU' => $transfer1['sku'],//'品號',
                        'LotId' => $transfer1['lotid'],//'批號',
                        'CheckQty' => $transfer1['checkqty'],//'驗收數量'
                        'TransferOutWarehouse' => $transfer1['warehouse_out'],//'轉出庫',
                        'TransferInWarehouse' => $transfer1['warehouse_in'],//'轉入庫'
                    );
                    $num++;
                }
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $transfer1list = \app\admin\model\ela\Transfer1::where('state', '0')->where('transfer0_id', $row['transfer0_id'])->select();
                    foreach ($transfer1list as $m => $transfer1) {
                        $transfer1->state = 1;
                        $transfer1->result = 1;
                        $transfer1->save();
                    }
                }
            }
        }
    }

    //http://ela.test/api/ela/data9
    //銷退單
    public function data9() {
        $sql = "select returndan09h_id from fa_ela_returndan09 where state = '0' group by returndan09h_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendSellBackData',
            'SellBackDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $rd09h0 = \app\admin\model\ela\Returndan09h::get($row['returndan09h_id']);
            if (!$rd09h0)
                continue;

            $SellBackDataInfo = "SellBackDataInfo[{$k}]";
            $data['SellBackDataList'][$SellBackDataInfo] = array(
                'POType' => $rd09h0['receipt'],//'單別',
                'POId' => $rd09h0['receipt_number'],//'單號',
                'ReturnDateTime' => $rd09h0['date'],//'入庫日期',
                'FactoryId' => $rd09h0['factory'],//'廠別代號',
                'SellDetailDataList' => []
            );

            $rd091list = \app\admin\model\ela\Returndan09::where('state', '0')
                ->where('warehouse', '6408')
                ->where('returndan09h_id', $row['returndan09h_id'])->select();
            foreach ($rd091list as $m => $rd091) {
                $SellBackDetailDataInfo = "SellBackDetailDataInfo[{$m}]";
                $data['SellBackDataList'][$SellBackDataInfo]['SellBackDetailDataList'][$SellBackDetailDataInfo] = array(
                    'SerialId' => $rd091['serialid'],//'序號',
                    'SKU' => $rd091['sku'],//'品號',
                    'LotId' => $rd091['lotid'],//'批號',
                    'CheckQty' => $rd091['checkqty'],//'驗收數量'
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $rd091list = \app\admin\model\ela\Returndan09::where('state', '0')->where('returndan09h_id', $row['returndan09h_id'])->select();
                    foreach ($rd091list as $m => $rd091) {
                        $rd091->state = 1;
                        $rd091->result = 1;
                        $rd091->save();
                    }
                }
            }
        }
    }

    //http://ela.test/api/ela/data10
    //退貨單
    public function data10() {
        $sql = "select returndan11h_id from fa_ela_returndan11 where state = '0' group by returndan11h_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendBuyReturnData',
            'BuyReturnDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $rd11h0 = \app\admin\model\ela\Returndan11h::get($row['returndan11h_id']);
            if (!$rd11h0)
                continue;

            $BuyReturnDataInfo = "BuyReturnDataInfo[{$k}]";
            $data['BuyReturnDataList'][$BuyReturnDataInfo] = array(
                'POType' => $rd11h0['receipt'],//'單別',
                'POId' => $rd11h0['receipt_number'],//'單號',
                'ReturnDateTime' => $rd11h0['date'],//'入庫日期',
                'FactoryId' => $rd11h0['factory'],//'廠別代號',
                'BuyReturnDetailDataList' => []
            );

            $rd111list = \app\admin\model\ela\Returndan11::where('state', '0')
                ->where('warehouse', '6408')
                ->where('returndan11h_id', $row['returndan11h_id'])->select();
            foreach ($rd111list as $m => $rd111) {
                $BuyReturnDetailDataInfo = "BuyReturnDetailDataInfo[{$m}]";
                $data['BuyReturnDataList'][$BuyReturnDataInfo]['BuyReturnDetailDataList'][$BuyReturnDetailDataInfo] = array(
                    'SerialId' => $rd111['serialid'],//'序號',
                    'SKU' => $rd111['sku'],//'品號',
                    'LotId' => $rd111['lotid'],//'批號',
                    'CheckQty' => $rd111['checkqty'],//'驗收數量'
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $rd111list = \app\admin\model\ela\Returndan11::where('state', '0')->where('returndan11h_id', $row['returndan11h_id'])->select();
                    foreach ($rd111list as $m => $rd111) {
                        $rd111->state = 1;
                        $rd111->result = 1;
                        $rd111->save();
                    }
                }
            }
        }
    }

    //http://ela.test/api/ela/data11
    //銷貨單 fa_ela_returndan08h fa_ela_returndan08
    public function data11() {

        $sql = "select returndan08h_id from fa_ela_returndan08 where state = '0' group by returndan08h_id";
        $idlist = Db::query($sql);

        $data = [
            'WebService_ID' => 'ERP',
            'EventID' => 'SendSellData',
            'SellDataList' => []
        ];

        $num = 0;
        foreach ($idlist as $k => $row ) {
            $rd08h0 = \app\admin\model\ela\Returndan08h::get($row['returndan08h_id']);
            if (!$rd08h0)
                continue;

            $SellDataInfo = "SellDataInfo[{$k}]";
            $data['SellDataList'][$SellDataInfo] = array(
                'POType' => $rd08h0['receipt'],//'單別',
                'POId' => $rd08h0['receipt_number'],//'單號',
                'ReturnDateTime' => $rd08h0['date'],//'入庫日期',
                'FactoryId' => $rd08h0['factory'],//'廠別代號',
                'SellDetailDataList' => []
            );

            $rd081list = \app\admin\model\ela\Returndan08::where('state', '0')
                ->where('warehouse', '6408')
                ->where('returndan08h_id', $row['returndan08h_id'])->select();
            foreach ($rd081list as $m => $rd081) {
                $SellDetailDataInfo = "SellDetailDataInfo[{$m}]";
                $data['SellDataList'][$SellDataInfo]['SellDetailDataList'][$SellDetailDataInfo] = array(
                    'SerialId' => $rd081['serialid'],//'序號',
                    'SKU' => $rd081['sku'],//'品號',
                    'LotId' => $rd081['lotid'],//'批號',
                    'CheckQty' => $rd081['checkqty'],//'驗收數量'
                );
                $num++;
            }
        }

        unset($row);

        if ($num > 0) {
            $strData = "<eWMSMessage>" . $this->arrayToXml($data) . "</eWMSMessage>";
            if ($this->sendsoap($strData)) {
                foreach ($idlist as $row) {
                    $rd081list = \app\admin\model\ela\Returndan08::where('state', '0')->where('returndan08h_id', $row['returndan08h_id'])->select();
                    foreach ($rd081list as $m => $rd081) {
                        $rd081->state = 1;
                        $rd081->result = 1;
                        $rd081->save();
                    }
                }
            }
        }

    }

    //http://ela.test/api/ela/data12
    //盤點資料
    public function data12() {
        $data = ['WebService_ID' => 'ERP', 'EventID' => 'SendInventoryData',
            'InventoryDataList' =>
                ['InventoryDataInfo' =>
                    ['POId' => '盤點底稿編號',
                        'InventoryDetailDataList' =>
                            ['InventoryDetailDataInfo' =>
                                ['0' => ['SerialId' => '盤點底稿序號', 'SKU' => '品號', 'LotInventory' => '批號盤點', 'LotId' => '批號', 'InventoryQty' => '盤點數量'],
                                    '1' => ['SerialId' => '盤點底稿序號', 'SKU' => '品號', 'LotInventory' => '批號盤點', 'LotId' => '批號', 'InventoryQty' => '盤點數量']
                                ]
                            ]
                    ]
                ]
        ];

        $strData = "<eWMSMessage>".$this->arrayToXml($data)."</eWMSMessage>";
        $this->success('返回成功', $strData);
//        echo '<br>' . $strData;
    }

    //http://ela.test/api/ela/data13
    //盤點單回報
    public function data13() {
        $data = ['WebService_ID' => 'ERP', 'EventID' => 'InventoryData',
            'InventoryDataList' =>
                ['InventoryDataInfo' =>
                    ['Inventory_ID' => '盤點單編號',
                        'InventoryDetailDataList' =>
                            ['InventoryDetailDataInfo' =>
                                ['0' => ['SerialId' => '盤點底稿序號', 'SKU' => '品號', 'CarrierID' => '棧板編號', 'LotId' => '批號', 'InventoryQty' => '盤點數量'],
                                    '1' => ['SerialId' => '盤點底稿序號', 'SKU' => '品號', 'CarrierID' => '棧板編號', 'LotId' => '批號', 'InventoryQty' => '盤點數量']
                                ]
                            ]
                    ]
                ]
        ];

        $strData = "<eWMSMessage>".$this->arrayToXml($data)."</eWMSMessage>";
        $this->success('返回成功', $strData);
//        echo '<br>' . $strData;
    }


    //http://ela.test/api/ela/setmainlist
    //插入，非修改；修改在上传后
    public function setmainlist()
    {
        set_time_limit(0); //执行时间无限
        ini_set('memory_limit', '-1'); //内存无限

        ob_end_clean();
        ob_implicit_flush();
        header('X-Accel-Buffering: no');

        echo '#Begin' . date('H:i:s') . '<br>';

        $today = date('Y-m-d');
//        $today = "2019-10-01";
        for ($i = 0; $i < 8; $i++) {
            $tname = "fa_ela_deposit0";
            $kind = $i."";
            switch($i) {
                default:
                case 0:
                    break;
                case 1:
                    $tname = "fa_ela_productdeposit0";
                    break;
                case 2:
                    $tname = "fa_ela_returndan0";
                    break;
                case 3:
                    $tname = "fa_ela_returndan09h";
                    break;
                case 4:
                    $tname = "fa_ela_picking0";
                    break;
                case 5:
                    $tname = "fa_ela_returndan08h";
                    break;
                case 6:
                    $tname = "fa_ela_returndan11h";
                    break;
                case 7:
                    $tname = "fa_ela_transfer0";
                    break;
            }
            //select * from fa_ela_deposit0 where date >= '2021-09-17' and id not IN (SELECT receipt_id from fa_ela_mainlist where kind = '0' and date >= '2021-09-17')
            $sql = "select * from {$tname} where update_time >= '{$today}' and id not IN (SELECT receipt_id from fa_ela_mainlist where kind = '{$kind}' and update_time >= '{$today}') ";
            $list = Db::query($sql);
            foreach ($list as $row) {
                $main = new \app\admin\model\ela\Mainlist;
                $main->kind = $kind;
                if (isset($row['stock'])) {
                    $main->stock = $row['stock'];
                }
                $main->receipt_id = $row['id'];
                $main->receipt = $row['receipt'];
                $main->receipt_number = $row['receipt_number'];
                $main->date = $row['date'];
                $main->receipt_name = $row['receipt_name'];
                $main->note = $row['note'];
                $main->save();
            }

        }

        echo '<br>#OK ' . date('H:i:s') . '<br>';
    }

    //http://ela.test/api/ela/updatemainlist
    //更新
    public function updatemainlist()
    {
        set_time_limit(0); //执行时间无限
        ini_set('memory_limit', '-1'); //内存无限

        ob_end_clean();
        ob_implicit_flush();
        header('X-Accel-Buffering: no');

        echo '#Begin' . date('H:i:s') . '<br>';

        $list = \app\admin\model\ela\Mainlist::where('status', '0')->select();
        foreach ($list as &$row) {
            $kind = intval($row['kind']);
            switch($kind) {
                default:
                case 0:
                    $sql = "select * from fa_ela_deposit1 where deposit0_id = {$row['receipt_id']}";
                    break;
                case 1:
                    $sql = "select * from fa_ela_productdeposit1 where productdeposit0_id = {$row['receipt_id']}";
                    break;
                case 2:
                    $sql = "select * from fa_ela_returndan1 where returndan0_id = {$row['receipt_id']}";
                    break;
                case 3:
                    $sql = "select * from fa_ela_returndan09 where returndan09h_id = {$row['receipt_id']}";
                    break;
                case 4:
                    $sql = "select * from fa_ela_picking1 where picking0_id = {$row['receipt_id']}";
                    break;
                case 5:
                    $sql = "select * from fa_ela_returndan08 where returndan08h_id = {$row['receipt_id']}";
                    break;
                case 6:
                    $sql = "select * from fa_ela_returndan11 where returndan11h_id = {$row['receipt_id']}";
                    break;
                case 7:
                    $sql = "select * from fa_ela_transfer1 where transfer0_id = {$row['receipt_id']}";
                    break;
            }
            $list1 = Db::query($sql);
            foreach ($list1 as $row1) {
                if (intval($row1['state']) == 1) {
                    $row['status'] = "1";
                    if (intval($row1['result']) == 1) {
                        $row['status'] = "2";
                    }
                    $row->save();
                }
                break;
            }
            $row->save();
        }

        echo '<br>#OK ' . date('H:i:s') . '<br>';
    }

    //回报0 -- 單據狀態回報格式
    //http://ela.test/api/ela/return0
    public function return0() {
        $xml = "
<STD_IN>
	<ProdID>WMS</ProdID>
	<Companyid>Leader</Companyid>
	<Userid>DS</Userid>
	<DoAction>CMSAB01</DoAction>
	<Docase>1</Docase>
	<Data>
		<FormHead>
			<TableName>INVI02</TableName>
			<RecordList>
				<MO001>新品號</MO001>
				<MO200>-1</MO200>
			</RecordList>
			<TableName>PURI09</TableName>
			<RecordList>
				<PU001>進貨單單別</PU001>
				<PU002>進貨單單號</PU002>
				<PU200>-1</PU200>					\
			</RecordList>
			<TableName>COPI08</TableName>
			<RecordList>
				<CO001>銷貨單單別</CO001>
				<CO002>銷貨單單號</CO002>
				<CO200>-1</CO200>
			</RecordList>
			<TableName>MOCI05</TableName>
			<RecordList>
				<MP001>生產入庫單單別</MP001>
				<MP002>生產入庫單單號</MP002>
				<MP200>-1</MP200>
			</RecordList>
			<TableName>MOCI03</TableName>
			<RecordList>
				<MU001>領料單單別</MU001>
				<MU002>領料單單號</MU002>
				<MU200>-1</MU200>
			</RecordList>
			<TableName>MOCI04</TableName>
			<RecordList>
				<MR001>退料單單別</MR001>
				<MR002>退料單單號</MR002>
				<MR200>-1</MR200>
			</RecordList>
			<TableName>COPI09</TableName>
			<RecordList>
				<CR001>銷退單單別</CR001>
				<CR002>銷退單單號</CR002>
				<CR200>-1</CR200>
			</RecordList>
			<TableName>INVI08</TableName>
			<RecordList>
				<IN001>調撥單單別</IN001>
				<IN002>調撥單單號</IN002>
				<IN200>-1</IN200>
			</RecordList>
			<TableName>PURI11</TableName>
			<RecordList>
				<PR001>退貨單單別</PR001>
				<PR002>退貨單單號</PR002>
				<PR200>-1</PR200>
			</RecordList>
			<TableName>INVSO</TableName>
			<RecordList>
				<IS001>盤點單單別</IS001>
				<IS002>盤點單單號</IS002>
				<IS200>-1</IS200>
			</RecordList>
		</FormHead>
	</Data>
</STD_IN>";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报1 -- 進貨單回報
    //http://ela.test/api/ela/return1
    public function return1() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>BuyData</EventID>
	<BuyDataList>
		<BuyDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<BuyDateTime>採購日期</BuyDateTime>
			<FactoryId>廠別代號</FactoryId>
			<BuyDetailDataList>
				<BuyDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
				</BuyDetailDataInfo>
				<BuyDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
				</BuyDetailDataInfo>
			</BuyDetailDataList>
		</BuyDataInfo>
	</BuyDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报2 -- 銷貨單回報
    //http://ela.test/api/ela/return2
    public function return2() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>SellData</EventID>
	<SellDataList>
		<SellDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<SellDateTime>銷貨日期</SellDateTime>
			<FactoryId>廠別代號</FactoryId>
			<SellDetailDataList>
				<SellDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</SellDetailDataInfo>
				<SellDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</SellDetailDataInfo>
			</SellDetailDataList>
		</SellDataInfo>
	</SellDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
//        foreach ($data['SellDataList'] as $row) {
//            echo $row['POType']." ".$row['POId'];
//        }
    }

    //回报3 -- 生產入庫單回報
    //http://ela.test/api/ela/return3
    public function return3() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>ProduceInData</EventID>
	<ProduceInDataList>
		<ProduceInDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<ProduceInDateTime>生產入庫日期</ProduceInDateTime>
			<FactoryId>廠別代號</FactoryId>
			<ProduceInDetailDataList>
				<ProduceInDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</ProduceInDetailDataInfo>
				<ProduceInDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</ProduceInDetailDataInfo>
			</ProduceInDetailDataList>
		</ProduceInDataInfo>
	</ProduceInDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报4 -- 領料單回報
    //http://ela.test/api/ela/return4
    public function return4() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>PickUpData</EventID>
	<PickUpDataList>
		<PickUpDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<PickUpTime>領料日期</PickUpTime>
			<FactoryId>廠別代號</FactoryId>
			<PickUpDetailDataList>
				<PickUpDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</PickUpDetailDataInfo>
				<PickUpDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</PickUpDetailDataInfo>
			</PickUpDetailDataList>
		</PickUpDataInfo>
	</PickUpDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报5 -- 退料單回報
    //http://ela.test/api/ela/return5
    public function return5() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>ReturnData</EventID>
	<ReturnDataList>
		<ReturnDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<ReturnDateTime>退料日期</ReturnDateTime>
			<FactoryId>廠別代號</FactoryId>
			<ReturnDetailDataList>
				<ReturnDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</ReturnDetailDataInfo>
				<ReturnDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</ReturnDetailDataInfo>
			</ReturnDetailDataList>
		</ReturnDataInfo>
	</ReturnDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报6 -- 銷退單回報
    //http://ela.test/api/ela/return6
    public function return6() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>SellBackData</EventID>
	<SellBackDataList>
		<SellBackDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<ReturnDateTime>銷退日期</ReturnDateTime>
			<FactoryId>廠別代號</FactoryId>
			<SellBackDetailDataList>
				<SellBackDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</SellBackDetailDataInfo>
				<SellBackDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
					<WO_ID>工單號</WO_ID>
				</SellBackDetailDataInfo>
			</SellBackDetailDataList>
		</SellBackDataInfo>
	</SellBackDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报7 -- 調撥單回報
    //http://ela.test/api/ela/return7
    public function return7() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>TransferData</EventID>
	<TransferDataList>
		<TransferDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<ReturnDateTime>退料日期</ReturnDateTime>
			<FactoryId>廠別代號</FactoryId>
			<TransferDetailDataList>
				<TransferDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>批號</LotId>
					<CheckQty>驗收數量</CheckQty>
					<TransferOutWarehouse>轉出庫</TransferOutWarehouse>
					<TransferInWarehouse>轉入庫</TransferInWarehouse>
				</TransferDetailDataInfo>
				<TransferDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>批號</LotId>
					<CheckQty>驗收數量</CheckQty>
					<TransferOutWarehouse>轉出庫</TransferOutWarehouse>
					<TransferInWarehouse>轉入庫</TransferInWarehouse>
				</TransferDetailDataInfo>
			</TransferDetailDataList>
		</TransferDataInfo>
	</TransferDataList>
</eWMSMessage>						";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报8 -- 退貨單回報
    //http://ela.test/api/ela/return8
    public function return8() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>BuyReturnData</EventID>
	<BuyReturnDataList>
		<BuyReturnDataInfo>
			<POType>單別</POType>
			<POId>單號</POId>
			<BuyReturnDateTime>退貨日期</BuyReturnDateTime>
			<FactoryId>廠別代號</FactoryId>
			<BuyReturnDetailDataList>
				<BuyReturnDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
				</BuyReturnDetailDataInfo>
				<BuyReturnDetailDataInfo>
					<SerialId>序號</SerialId>
					<SKU>品號</SKU>
					<LotId>專案代碼</LotId>
					<CheckQty>驗收數量</CheckQty>
				</BuyReturnDetailDataInfo>
			</BuyReturnDetailDataList>
		</BuyReturnDataInfo>
	</BuyReturnDataList>
</eWMSMessage>								";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //回报9 -- 盤點單回報
    //http://ela.test/api/ela/return9
    public function return9() {
        $xml = "<eWMSMessage>
	<WebService_ID>ERP</WebService_ID>
	<EventID>InventoryData</EventID>
	<InventoryDataList>
		<InventoryDataInfo>
			<POId>盤點底稿編號</POId>
			<InventoryDetailDataList>
				<InventoryDetailDataInfo>
					<SerialId>盤點底稿序號</SerialId>
					<SKU>品號</SKU>
					<CarrierID>棧板編號</CarrierID>
					<LotId>專案代碼</LotId>
					<InventoryQty>盤點數量</InventoryQty>
				</InventoryDetailDataInfo>
				<InventoryDetailDataInfo>
					<SerialId>盤點底稿序號</SerialId>
					<SKU>品號</SKU>
					<CarrierID>棧板編號</CarrierID>
					<LotId>專案代碼</LotId>
					<InventoryQty>盤點數量</InventoryQty>
				</InventoryDetailDataInfo>
			</InventoryDetailDataList>
		</InventoryDataInfo>
	</InventoryDataList>
</eWMSMessage>					";
        $data = $this->xmlToArray($xml);
        $code = $this->dd_array2str($data);
        echo $code.'<br>';
    }

    //http://ela.test/api/ela/getxml?xml=faf
    public function getxml($xml)
    {
//        echo $xml.'----getxml<br>';
        return $xml.'----getxml1';
    }

}

//<eWMSMessage>
//	<ReportData>
//		<Result>Y</Result>
//		<ResultMessage></ResultMessage>
//	</ReportData>
//</eWMSMessage>